/* eslint valid-jsdoc: "off" */

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
const fileExtensions = [
  '.txt', '.doc', '.docx', '.pdf', '.rtf', '.odt', '.md', '.tex',
  '.jpg', '.png', '.gif', '.bmp', '.tif', '.svg',
  '.mp3', '.wav', '.aac', '.wma', '.ogg', '.flac',
  '.mp4', '.mov', '.webm', '.avi', '.wmv', '.mkv', '.flv', '.m4v',
  '.zip', '.rar', '.7z', '.tar.gz', '.iso',
  '.mdb', '.accdb', '.sql', '.dbf',
  '.exe', '.dll', '.jar', '.apk', '.app',
  '.html', '.htm', '.php', '.asp', '.jsp',
  '.xls', '.xlsx', '.csv', '.ods', '.numbers',
  '.ppt', '.pptx', '.key', '.odp', '.pps',
  '.ts', '.tsx', '.vue', '.java', '.json', '.xml', '.html', '.css', '.less', '.sass', '.yml',
];

module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  require('dotenv').config();
  const config = (exports = {});

  config.multipart = {
    mode: 'file',
    fileExtensions,
  };

  config.onerror = {
    all(_err, ctx) {
      // 在此处定义针对所有响应类型的错误处理方法
      // 注意，定义了 config.all 之后，其他错误处理方法不会再生效
      ctx.body = 'error';
      ctx.status = 500;
    },
    html(_err, ctx) {
      // html hander
      ctx.body = '<h3>error</h3>';
      ctx.status = 500;
    },
    json(_err, ctx) {
      // json hander
      ctx.body = { message: 'error' };
      ctx.status = 500;
    },
  };


  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1711333773902_5233';

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  // cros允许请求
  config.security = {
    csrf: {
      enable: false,
    },
    domainWhiteList: [ '*' ], // 允许访问域名的白名单,*表示都能访问
  };

  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
    credentials: true,
  };


  return {
    ...config,
    ...userConfig,
  };
};
